﻿<style>
ol.timeline{
        list-style:none;font-size:1.2em;
    }
    ol.timeline li{
        position:relative;
        padding:.3em 0 .6em .3em;
        line-height:1.1em;       
        margin-bottom:3px;
        text-align:justify;
        display: inline-block;
        width: 97.5%
    }
    .panel { display:none; }

    .b_breadcrumb{
        display: inline-block;
        width:100%;
    }
    .col_20{
        float: left;
        width: 20%;
    }
    .g_image{
        text-align: center;
    }
	.hide{display:none;}
	.unviewRecomment{
		color: green;
		display: table-row;
	}
	.unviewRecomment .unviewRecommentStar {
		color: red;
		fot-weight: bolder;
		font-size: 10px;
		display: table-cell;
		vertical-align: middle;
		margin-right: 5px;
	}
	.unviewRecomment .unviewRecommentStar .unviewRecommentContent{
		display: table-cell;
		vertical-align: middle;
	}
</style>
<?php
		$this->headTitle($this->translator('partner_title'));
?>		
<?php
    $enterprise = $this->enterprise;
    $arrRoute = array(
        'enterprise_id' => $enterprise->id,
        'enterprise_name' => Tomato_Utility_String::removeSign($enterprise->company_name_en, '-', true)
    );

	// UPDATE RECOMMENT VIEW 							
	$conn = Tomato_Db_Connection::factory()->getMasterConnection();
	$recommentDao  = Tomato_Model_Dao_Factory::getInstance()->setModule('bizprofile')->getPartnerDao();
	$recommentDao->setDbConnection($conn);
	$recommentDao->updateNotifyUnreadRecomment($enterprise->id);	
?>
<!-- Được quyền xem Partner -->
<?php if(!$this->permission || $this->permission->partner_permission  == 1 || $this->permission_viewall == 1) {?>
<div class="subcolumns tabs pb10">
    <ul class="tabNavigation">
        <li><a href="#" class="selected"><?php echo $this->translator('enterprise_is_partner')?></a></li>
		<?php if($this->isLogin && $this->isUserOfEnt):?>
        <li><a href="<?php echo $this->url($arrRoute, 'bizprofile_partner_waiting');?>"><?php echo $this->translator('enterprise_request_partner')?></a></li>
        <li><a href="<?php echo $this->url($arrRoute, 'bizprofile_partner_pending');?>"><?php echo $this->translator('enterprise_pending_partner')?></a></li>
		<?php endif;?>
    </ul>
</div>
<?php if(count($this->partners) > 0): ?>
<div class="t_news_tag notify" id="tab1">
	<?php 
		$newArr = array();
		foreach ($this->partners as $row)
			if($row->frontend_active ==1 && $row->deleted !=1)
				$newArr[] = $row;		
		foreach ($this->partners as $row)
			if($row->frontend_active  != 1 && $row->deleted !=1)
				$newArr[] = $row;		
		foreach ($this->partners as $row)
			if(($row->frontend_active != 1 && $row->deleted == 1) || ($row->frontend_active !== 1 && $row->deleted == 1))
				$newArr[] = $row;
	?>
	<?php foreach ($newArr as $row) :?>
	<div class="notify-item " style="height:auto;">
		<div class="item" style="height:auto;">
			<div class="b_post">
				<?php
					$arrParamEnterprise = array(
						'enterprise_id' => $row->enterprise_id,
						'enterprise_name' => Tomato_Utility_String::removeSign($row->company_name_en, '-', true)
					);
				?>
				<a href="
				<?php 
					if($row->frontend_active ==1 && $row->deleted !=1) { 
						echo $this->url($arrParamEnterprise, 'bizprofile_enterprise_index'); 
					} 
					else if($row->frontend_active  != 1 && $row->deleted !=1){
						echo "#";
					}
					else if(($row->frontend_active != 1 && $row->deleted == 1) || ($row->frontend_active !== 1 && $row->deleted == 1)){
						echo "#";
					}
				?>">
				<?php echo $this->lang == "en" ? $row->company_name_en : $row->company_name_vn; ?>
				</a>					
			</div>
			<div>
				<div style="clear:both;text-align:right;">
					<span style="float:left;display:relative;"><b>email</b> : <?php echo $row->contact_email ?> &nbsp; <b>tel</b> : <?php echo $row->contact_tel ?></span>			
			
					<span style="">
						<?php 
						if($row->partner_status == 'no')  echo $this->translator('partner_waiting_response');
						elseif($row->partner_status == 'pending')   echo $this->translator('partner_pending');
						else  echo $this->translator('partner_in_relationship');
						?>
					</span>	
					<?php 
						/**
						* Đối tác viết bài cho doanh nghiệp của mình
						*/
						$recomment = $this->recomments[$row->enterprise_id][0];							
						
						/**
						* Doanh nghiệp trả lời đối tác
						*/
						$replyRecomment = $this->replyRecomments[$row->enterprise_id][0];
					?>					
					<!--User được quyền viết giới thiệu -->
					<?php if((empty($replyRecomment->recomment)) && (empty($recomment->recomment)) && $this->isLogin && $this->isUserOfEnt && $this->allow('recomment') ): ?>					
					<span >
						<a class ="writeIntroduce" rel="<?php echo $row->enterprise_id ?>" href="javascript:void(0);"><?php echo $this->translator('enterprise_writeIntroduce_partner');?></a>
					</span>
					
					<?php endif;?>
					<span style="display:relative;float:right;margin-left:5px;">		
						<?php if($this->isLogin && $this->isUserOfEnt && $this->allow('remove-partner')):?>
							<form id="removePartner_<?php echo $row->enterprise_id;?>" method="post" action="<?php echo $this->url(array(), 'bizprofile_partner_remove_partner'); ?>" >
								<input type="hidden" name="enterprise_id" value="<?php echo $enterprise->id ?>" />
								<input type="hidden" name="relation_id" value="<?php echo $row->enterprise_id; ?>" />	
								<input type="hidden" name="partnerAction" value="list"/>
								<a class="partnerRemove" rel="<?php echo $row->enterprise_id;?>" href="javascript:void(0)">
									<?php echo $this->translator('enterprise_delete_partner');?>
								</a>							
							</form>
						<?php endif;?>						
					</span>					
				</div>			
				<!--Cho hiện trạng thái hoạt động của doanh nghiệp-->    
					<?php if(($row->frontend_active != 1 && $row->deleted == 1) || ($row->frontend_active !== 1 && $row->deleted == 1)): ?>
						<div>
							<h5 style="color:red;"><?php echo $this->translator('enterprise_deleted_partner');?></h5>
						</div>
					<?php endif; ?>
					
					<?php if($row->frontend_active  != 1 && $row->deleted !=1): ?>
						<div>
							<h5 style="color:red;"><?php echo $this->translator('enterprise_fontendactive_partner');?></h5>
						</div>
					<?php endif; ?>
				
		
				<div style="width:100%;">
					<span style = "float:right;">
						<!-- USER ĐƯỢC REPLY RECOMMENT -->
						<?php if((!empty($recomment->recomment)) && (empty($replyRecomment->recomment) && $this->isLogin && $this->isUserOfEnt && $this->allow('replyrecomment')) ): ?>
							<a class ="reply" rel="<?php echo $row->enterprise_id ?>" href="javascript:void(0);">
								<?php echo $this->translator('enterprise_reply_partner');?>
							</a>
						<?php endif;?>
					</span>
					<span style="margin-left:5px;">	
						<?php if($recomment->notify == 'unview' && $recomment->recomment):
						?> 
							<span class="unviewRecomment">
								<span class="unviewRecommentStar">(New)&nbsp;</span>
								<span class="unviewRecommentContent"><?php echo $recomment->recomment;?></span>
							</span>
						<?php else:?>
							<?php echo $recomment->recomment;?></span>
						<?php endif;?>
					</span>
				</div>
			</div>
			
			<div style = "display:inline-block;width:100%;<?php if(empty($replyRecomment->recomment)) echo 'display:none;'; ?>" class="containerReplyRecomment">			
				<div style="width:10%;float:left;font-size:large;margin-top:-8px;text-align:right;">
					&rarr;&nbsp;
				</div>
				<div style="float:left;width:90%;">
					<!-- USER ĐƯỢC REPLY RECOMMENT -->
					<?php if(!empty($replyRecomment->recomment) && $this->isLogin && $this->isUserOfEnt && $this->allow('replyrecomment') )
								$dislay_editReply  = "block"; 
						  else $dislay_editReply   = "none"; 
					?>			
					<span style="float:right">						
						<a style="display:<?php echo $dislay_editReply ;?>" class ="editReply" rel="<?php echo $row->enterprise_id ?>" href="javascript:void(0);"><?php echo $this->translator('enterprise_edit_partner');?></a>
					</span>
					<div class="replyRecomment" style="width:95%" rel = "<?php echo $row->enterprise_id;?>" id = "replyRecomment_<?php echo $row->enterprise_id;?>">
						<?php echo $replyRecomment->recomment;?>
					</div>
				</div>
			</div>
			
			<div class ="hide" rel="<?php echo $row->enterprise_id;?>" id = "hide_<?php echo $row->enterprise_id;?>"  align="left" style="width:100%; margin-bottom:3px;padding-top:3px;disply:none">
				<form action="<?php echo $this->url(array(), 'bizprofile_partner_recomment');?>" method="post" id="partnerCommentFrm_<?php echo $row->enterprise_id;?>">                  
					<input type="hidden" name="enterprise_id" value="<?php echo $row->enterprise_id; ?>" />
					<input type="hidden" name="relation_id" value="<?php echo $enterprise->id ?>" />
					<div style="width:100%; margin-bottom:3px; ; padding-top:3px;text-align:right;">
						<textarea style="width:90%;height:23px;text-align:left;" size = '100' name="content" id="content_<?php echo $row->enterprise_id;?>"></textarea>
					</div>
					<div style="text-align:right; padding-right:5px; padding-top:5px;">
						<input type="button" value="<?php echo $this->translator('enterprise_submitreply_partner');?>" class="abc_comment_submit" rel="<?php echo $row->enterprise_id;?>"/>
					</div>
				</form>											
			</div>
		</div>
	</div>
	<?php endforeach; ?>
	<div class="paginator" style="margin-bottom: 10px;">
		<?php echo $this->paginator()->slide($this->paginator, $this->paginatorOptions); ?>
	</div>
</div>
<?php endif; ?>
<?php }else{?>
<div class="t_news_tag notify" id="tab1">
	<?php echo $this->translator('permission_allow_view_partner');?>
</div>
<?php }?>


<script type="text/javascript" src="<?php echo $this->APP_STATIC_SERVER; ?>/js/jquery.form/jquery.form.js"></script>	
<script type="text/javascript" charset="utf-8">
	$(".editReply").click(function(){
		var I = $(this).attr('rel');
		var data =$("#replyRecomment_"+I).text();
		data = $.trim(data);
		$("#hide_"+I).slideToggle("normal");
		$("#content_"+I).text(data);
	});
	$(".reply").click(function(){
		var I = $(this).attr('rel');
		$("#hide_"+I).slideToggle("normal");
	});
	
	$(".writeIntroduce").click(function(){
		var I = $(this).attr('rel');
		$("#hide_"+I).slideToggle("normal");
	});
	
	$(".partnerRemove").click(function(){
		if (confirm("<?php echo $this->translator('partner_remove_partner'); ?>"))
		{
			var rel = $(this).attr('rel');			
			$("#removePartner_"+rel).submit();
		}
	});
	
	$('.abc_comment_submit').click(function(){		
		self = this;		
		rel = $(self).attr('rel');
		var options = {
			target: '#replyRecomment_'+rel, // target element(s) to be updated with server response
			beforeSubmit:  showRequest,
			url: '<?php echo $this->url(array(), 'bizprofile_partner_recomment');?>',
			type: 'POST',  // pre-submit callback,
			success: function(html){
				$('.writeIntroduce').each(function(){
					if($(this).attr("rel") == rel){
						$(this).hide();
					}
				});
				$(".editReply").each(function(){
					if($(this).attr("rel") == rel){
						//writeIntroduce
						if($(this).parents('.containerReplyRecomment').css('display')=='none'){
							$(this).parents('.containerReplyRecomment')						
								   .show()
								   .css('display','inline-block');
							
						}
						$(this).show();
					}
				});
			},
			error: function(error){
			}
		};		
		$("#partnerCommentFrm_"+rel).ajaxSubmit(options);
		$(".hide").hide();
		$(".reply").hide();
		
	});	
	function showRequest(formData, jqForm, options) {
		var queryString = $.param(formData);
		return true;
	}
</script>